package zcj.stu.scheduling;

import lombok.Data;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import zcj.stu.util.http.HttpClientUtil;

import javax.annotation.Resource;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import static zcj.stu.util.http.HttpConstant.REQ_TIMES;

@Component
@Data
@RefreshScope
public class DaKaTiming {
    private final String cookieSuid="sduuid=114975103a0e7a3df5c9f82d51a2d290";
    @Resource
    private DynamicParamsConfig dynamicParamsConfig;
    @Scheduled(cron = "0 0 8 * * * ")
    public void Daka() {
        try {
            //url
            String url = dynamicParamsConfig.getUrl();
            // 请求体
            Map<String,String> body=dynamicParamsConfig.getParams();
            String format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date());
            body.put("dksj",format);
            String date = format.split(" ")[0];
            body.put("zjhsrq",date);
            // 额外设置请求头
            String cookie = dynamicParamsConfig.getCookie();
            cookie=cookie+"; "+cookieSuid;
            String result = HttpClientUtil.sendPostByForm(url, body, REQ_TIMES,cookie);
        } catch (Exception e) {
            e.printStackTrace();
        }
       /* System.out.println(body);
        try {
            System.out.println(URLDecoder.decode(body, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }*/
    }
//    @Scheduled(cron = "0 0 8 * * ?")
//    public void request(){
//          restTemplate.getForEntity("https://ehall.hljeu.edu.cn/xglyw/_web/_apps/poe/mrdk/dk.jsp?domainId=1",String.class);
//    }
}

